package com.moteur.analysersite.performance;

import java.io.IOException;
import java.net.MalformedURLException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class ConnexionSite extends Thread {
	String url;

	public ConnexionSite(String name, String url) {
		super(name);
		this.url = url;
	}
	

	public void run() {
		try {
			Document doc = Jsoup.connect(url).timeout(30 * 1000).get();
			synchronized (ThreadMoulinette.success) {
				ThreadMoulinette.success = ThreadMoulinette.success + 1;
			}
		} catch (MalformedURLException e) {
			synchronized (ThreadMoulinette.error) {
				ThreadMoulinette.error = ThreadMoulinette.error + 1;
			}
		} catch (IOException e) {
			synchronized (ThreadMoulinette.error) {
				ThreadMoulinette.error = ThreadMoulinette.error + 1;
			}
		}catch (Exception e) {
			synchronized (ThreadMoulinette.error) {
				ThreadMoulinette.error = ThreadMoulinette.error + 1;
			}
		}
		synchronized (ThreadMoulinette.overd) {
			ThreadMoulinette.overd = ThreadMoulinette.overd + 1;
			if(ThreadMoulinette.overd.intValue() == ThreadMoulinette.NumberThread.intValue()){
				ThreadMoulinette.writeResult();
			}else{
				synchronized (System.out) {
					System.out.println(ThreadMoulinette.overd);
				}
			}
		}
		
	}
}
